caught
and throw again
:guard (
S1
guard
S2
catching
e1: (repair A; caught A)
e2: (repair B; throw again)
e3: repair C
end
) catching
e4: repair D
e5: repair E
all: caught undefined
end
S3
If S2
reports an e1
exception, the
following happens:
S2
reports an e2
exception, the
following happens:e1
, which it is not.
e2
. Since it is, it executes the expression
repair B
. The throw again
expression
causes the exception to be thrown again immediately, which
means it stops checking catchers in the current catch list and
starts checking catchers in the catch list of the surrounding
guard
expression.
e4
.
e5
.
all: caught undefined
explicitly
catches the exception and prevents it from being thrown again.
guard
expression and continues on to expression S3
report
function
with two arguments:
For example, the format string for the
divideByZero
exception instance is "Attempt
to divide %* by zero"
where %*
will be
replaced by the number on which the attempt to divide by 0 was
made. For instance, when an attempt is made to divide 25 by 0,
a divideByZero
error is reported by the following
statement:
report divideByZero 25
The value 25 is passed to the exception's format string and the format string for the reported exception becomes:
"Attempt to divide 25 by zero."
The second argument to report
can be a collection
if you want to pass more than one object to the format string.
For example, the format string for the noMethod
exception requires two input values: the method that was
called and the class.
The following statement reports a noMethod
exception when an attempt is made to call the nonexistent
turnPurple
method on an instance of the class
Window
:
report noMethod #("turnPurple", Window)
When this code is executed, an exception is reported. The formatted result for the exception is:
No "turnPurple" method for Window.
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.